<template>
  <view v-if="show" class="modal-container">
    <view class="modal-overlay" @click="onCancel"></view>
    <view class="modal-content">
      <view class="modal-header" v-if="title">
        <text class="modal-title">{{ title }}</text>
      </view>
      <view class="modal-body">
        <text class="modal-text">{{ content }}</text>
      </view>
      <view class="modal-footer">
        <button 
          v-if="showCancel" 
          class="modal-btn cancel-btn" 
          @click="onCancel"
        >
          {{ cancelText }}
        </button>
        <button 
          class="modal-btn confirm-btn" 
          @click="onConfirm"
        >
          {{ confirmText }}
        </button>
      </view>
    </view>
  </view>
</template>

<script setup>
// 定义 props
const props = defineProps({
  // 是否显示
  show: {
    type: Boolean,
    default: false
  },
  // 标题
  title: {
    type: String,
    default: ''
  },
  // 内容
  content: {
    type: String,
    default: ''
  },
  // 是否显示取消按钮
  showCancel: {
    type: Boolean,
    default: true
  },
  // 确认按钮文字
  confirmText: {
    type: String,
    default: '确定'
  },
  // 取消按钮文字
  cancelText: {
    type: String,
    default: '取消'
  }
})

// 定义 emits
const emit = defineEmits(['cancel', 'confirm'])

// 方法
const onCancel = () => {
  emit('cancel')
}

const onConfirm = () => {
  emit('confirm')
}
</script>

<style scoped>
.modal-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 9999;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
}

.modal-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 80%;
  background-color: white;
  border-radius: 20rpx;
  overflow: hidden;
}

.modal-header {
  padding: 30rpx;
  text-align: center;
  border-bottom: 1rpx solid #eee;
}

.modal-title {
  font-size: 36rpx;
  font-weight: bold;
  color: #333;
}

.modal-body {
  padding: 30rpx;
  text-align: center;
}

.modal-text {
  font-size: 32rpx;
  color: #666;
  line-height: 1.5;
}

.modal-footer {
  display: flex;
  border-top: 1rpx solid #eee;
}

.modal-btn {
  flex: 1;
  padding: 20rpx 0;
  border: none;
  font-size: 32rpx;
  background-color: transparent;
}

.modal-btn:active {
  background-color: #f5f5f5;
}

.cancel-btn {
  color: #999;
  border-right: 1rpx solid #eee;
}

.confirm-btn {
  color: #007aff;
}
</style>